//
//  MineViewController.m
//  聊吧
//
//  Created by 刘洋 on 16/6/13.
//  Copyright © 2016年 刘洋. All rights reserved.
//

#import "MineViewController.h"
#import "MineHeadTableViewCell.h"
#import "MineTableViewCell.h"
#import "SettingsViewController.h"

//俩个cell的静态变量
static NSString *const mineHeadCell = @"mineHeadCell";
static NSString *const mineCell = @"mineCell";

@interface MineViewController ()<UITableViewDataSource,UITableViewDelegate>
//建立tableView
@property(nonatomic,retain)UITableView *mineTableView;

@end

@implementation MineViewController

- (void)dealloc
{
    [_mineTableView release];
 
    [super dealloc];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
      self.view.backgroundColor = [UIColor whiteColor];
   
    self.navigationItem.title = @"我";
    self.navigationController.navigationBarHidden = NO;
    self.navigationItem.hidesBackButton = YES;
    
    
    
    self.mineTableView = [[UITableView alloc]initWithFrame:[[UIScreen mainScreen]bounds] style:UITableViewStylePlain];
    self.mineTableView.backgroundColor = [UIColor grayColor];
    [self.view addSubview:self.mineTableView];
    [_mineTableView release];
    self.mineTableView.delegate = self;
    self.mineTableView.dataSource = self;
    self.mineTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    //注册俩种cell
    [self.mineTableView registerClass:[MineHeadTableViewCell class] forCellReuseIdentifier:mineHeadCell];
    [self.mineTableView registerClass:[MineTableViewCell class] forCellReuseIdentifier:mineCell];
    
    
    // Do any additional setup after loading the view.
}


#pragma mark cell的点击方法
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section == 2) {
        SettingsViewController *settingsVC = [[SettingsViewController alloc]init];
        settingsVC.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:settingsVC animated:YES];
        [settingsVC release];
        
    }
    
    
    
    
    
}


#pragma mark 设置section数量
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
    
}


#pragma mark tableView每个分区要显示的行数(cell的个数)必须实现的方法之一
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    if (section == 0) {
        return 1;
    }else if (section == 1){
        return 2;
        
    }else{
        return 1;
        
    }
    
    
}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
   
    if (indexPath.section == 2) {
           MineTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:mineCell forIndexPath:indexPath];
        cell.label.text = @"设置";
        cell.image.image = [UIImage imageNamed:@"SZ"];
        cell.arrow.image = [UIImage imageNamed:@"JT"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
        
    }
    if (indexPath.section == 1) {
     
        MineTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:mineCell forIndexPath:indexPath];
        
        NSArray *array = @[@"相册",@"收藏"];
        NSArray *arrayPics = [NSArray arrayWithObjects:[UIImage imageNamed:@"PG"],[UIImage imageNamed:@"SC"],nil];
        cell.label.text = array[indexPath.row];
        //图片
        cell.image.image = arrayPics[indexPath.row];
        //箭头
        cell.arrow.image = [UIImage imageNamed:@"JT"];
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
        
    }
    
    
    MineHeadTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:mineHeadCell forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.arrow.image = [UIImage imageNamed:@"JT"];
    return cell;
    
}

//cell高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section == 0) {
        return 100;
    }else {
        return 50;
        
    }
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 20;


}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
